cmake_minimum_required(VERSION 2.6)

project(yolov5)

add_definitions(-std=c++17)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_CUDA_ABI_COMPILED TRUE)
set(CMAKE_CUDA_COMPILER_ID "Clang")
set(CMAKE_CUDA_COMPILER "clang++" CACHE STRING "CUDA compiler.")
set(CMAKE_CUDA_HOST_COMPILER "clang++" CACHE STRING "CUDA Host compiler.")
if (NOT CMAKE_CUDA_ARCHITECTURES)
    set(CUDA_ARCH "ivcore11" CACHE STRING "CUDA architecture.")
    set(CMAKE_CUDA_ARCHITECTURES "ivcore11")
endif()
enable_language(CUDA)

include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/corex/include)
link_directories(/usr/local/corex/lib64)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")

add_library(myplugins SHARED ${PROJECT_SOURCE_DIR}/yololayer.cu)
target_link_libraries(myplugins ixrt ixrt_plugin cudart)

find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(yolov5 ${PROJECT_SOURCE_DIR}/calibrator.cpp ${PROJECT_SOURCE_DIR}/yolov5.cpp)
target_link_libraries(yolov5 ixrt)
target_link_libraries(yolov5 cudart)
target_link_libraries(yolov5 myplugins)
target_link_libraries(yolov5 ${OpenCV_LIBS})

if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)

